<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
	<title></title>
	<link rel="stylesheet" href="/public/css/common.css">
	<link rel="stylesheet" href="/public/layui/css/layui.css">
	<script src="/public/js/jquery.min.js"></script>
	<script src="/public/js/xadmin.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>

<body>
	<div class="page-content layui-anim layui-anim-upbit">
		<h2>管理员管理</h2>
		<!-- 操作栏 -->
		<div class="yg-block">
			<div>
				<button class="layui-btn" onclick="x_admin_show('添加管理员','/admin/add_admin',600,400)">
					<i class="layui-icon">&#xe61f;</i>
					<span>添加</span>
				</button>
			</div>
			<span class="x-right" style="line-height:40px">共有数据：<%= adminList.length %> 条</span>
		</div>

		<!-- 列表栏 -->
		<table class="layui-table">
			<thead>
				<tr>
					<th>ID</th>
					<th>账号</th>
					<th>角色名</th>
					<th>加入时间</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{{each adminList}}
				<tr>
					<td>{{$value.id}}</td>
					<td>{{$value.name}}</td>
					{{ if $value.status == 1}}
					<td>超级管理员</td>
					{{else}}
					<td>普通管理员</td>
					{{/if}}
					<td class="td-status">{{$value.add_time}}</td>
					<td>
						<% if($value.is_open == 0){ %> 
						<span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" id="admin_id<%= $value.id %>">已禁用</span>
						<% } else {%>
						<span class="layui-btn layui-btn-normal layui-btn-mini" id="admin_id<%= $value.id %>">已启用</span>
						<% } %>
					</td>
					<td class="td-manage">
						{{ if $value.status != 1}}
						<% if($value.is_open == 0){ %> 
						<a onclick="member_stop(this, '<%= $value.id %>')" href="javascript:;" title="启用">
							<i class="layui-icon">&#xe62f;</i>
						</a>
						<% } else {%>
							<a onclick="member_stop(this, '<%= $value.id %>')" href="javascript:;" title="禁用">
								<i class="layui-icon">&#xe601;</i>
							</a>
						<% } %>
						{{/if}}
						<a title="查看编辑" onclick="x_admin_show('编辑','/admin/update_admin/<%= $value.id %>',600,400)"
							href="javascript:;">
							<i class="layui-icon">&#xe642;</i>
						</a>
						{{ if $value.status != 1}}
						<a title="删除" onclick="del_admin('<%= $value.id %>')" href="javascript:;">
							<i class="layui-icon">&#xe640;</i>
						</a>
						{{/if}}
					</td>
				</tr>
				{{/each}}
			</tbody>
		</table>
	</div>
</body>
<script src="/public/layui/layui.js"></script>
<script src="/public/js/api.js"></script>
<script>
	/*用户-停用*/
	function member_stop(obj, id) {
		let title, is_open;
		if ($(obj).attr('title') == '启用') {
			title = '确认要启用吗？';
			is_open = '1';
		} else {
			title = '确认要停用吗？';
			is_open = '0';
		}
		layer.confirm(title, function (index) {
			_http.open_admin({
				is_open: is_open,
				id: id
			}, (res) => {
				if(res.code === 0) {
					layer.msg(res.msg,{icon: 1,time:1000});
					setTimeout(() => {
						location.reload();
					}, 1000)
				} else {
					layer.msg(res.msg,{icon: 2,time:2000});
				}
			})
		})
	}

	// 删除
	function del_admin(id) {
		layer.confirm('确认要删除吗？删除后将无法找回', function (index) {
			_http.del_admin({
				id: id
			}, (res) => {
				if (res.code === 0) {
					layer.msg(res.msg, { icon: 1, time: 1000 });
					setTimeout(() => {
						location.reload()
					}, 1000)
				} else {
					layer.msg(res.msg, { icon: 5, time: 1500 });
				}
			})
		});
	}
</script>

</html>